<template>
  <el-dialog :visible.sync="visible" :title="title" :close-on-click-modal="false" @opened="handleOpened" @closed="handleClosed">
    <div>
      <QupList :column="2" sep="：" default-value="" label-position="right" label-width="130">
        <QupListItem label="意向客户电话" :value="customerData.customerPhone" />
        <QupListItem label="意向客户姓名" :value="customerData.customerName" />
        <QupListItem label="所属办事处" :value="customerData.agencyName" />
        <QupListItem label="意向等级" :value="customerData.intendedLevel" dict-type-code="CTM_INTENTION_LEVEL" :prop-enum="{domainCode:'marketing',appCode:'slm'}" />
      </QupList>
      <el-form ref="form" :model="formData" :rules="formRules" label-width="100px">
        <el-form-item prop="investmentManagerId" label="招商经理">
          <c-common-search
            v-model="formData.investmentManagerId"
            url="/slm-ctm/api/v1/ctmInvestmentManager/page"
            method="POST"
            value-key="id"
            label-key="managerName"
            query-key="managerName"
            query-position="filtersRaw"
            operator="like"
            :columns="[
              {
                prop: 'managerAccount',
                label: '编码'
              },
              {
                prop: 'managerName',
                label: '姓名'
              }
            ]"
            :filters-raw="[
              { 'id': 'enable', 'property': 'enable', 'value': '1', 'operator': '=' }
            ]"
          />
        </el-form-item>
      </el-form>
      <div class="btn-end">
        <c-button type="default" @click="handleCancel">取消</c-button>
        <c-button type="primary" @click="handleConfirm">确定</c-button>
      </div>
    </div>
  </el-dialog>

</template>
<script>
import { reallocate } from '@/api/channelTask2/potentialCustomer'
export default {
  name: 'Reallocate',
  props: {
  },
  data() {
    return {
      visible: false,
      formData: {
        investmentManagerId: ''
      },
      formRules: {
        investmentManagerId: [{ required: true, message: '请选择招商经理', trigger: 'change' }]
      },
      customerData: {},
      title: '重新分配'
    }
  },
  computed: {
  },
  methods: {
    handleOpened() {
    },
    handleClosed() {
      this.customerData = {}
      this.title = '重新分配'
      this.$nextTick(() => {
        this.$refs.form && this.$refs.form.resetFields()
        this.$refs.form && this.$refs.form.clearValidate()
      })
    },
    openDialog(row, title = '重新分配') {
      this.customerData = row
      this.title = title
      this.visible = true
    },
    handleCancel() {
      this.visible = false
    },
    handleConfirm() {
      return this.$refs.form.validate().then(() => {
        const data = { ...this.formData }
        data.intendedCustomerId = this.customerData.id
        return reallocate(data).then(res => {
          this.$message.success('操作成功')
          this.visible = false
          this.$emit('on-success')
        })
      })
    }
  }
}
</script>
